<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://agi.corp.org/authz" prefix="authz"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="agi" %>
<%@ page import="th.co.mfec.mca.common.PrivConst"%>
<%@page import="th.co.mfec.mca.common.ProjectConstant"%>
<div id="content">
   <s:form id="mainForm" action="roleManagement-search.htm" method="post" >
   <s:hidden id="selectedId" name="selectedId" />
   <s:hidden id="currentPage" name="pagingBean.currentPage" value="%{pagingBean.currentPage}" />
   <s:hidden id="clickSearchFlag" name="clickSearchFlag" />
   <s:hidden id="sortMode" name="sortMode" />
      <div class="topic">Search User Group</div>
      <div id="searchForm" class="dataField">
      <div class="subTopic">Criteria Data</div>
      <div id="dialoginfo"></div>
          <div class="tableContent">
            <table>
              <tr>
                <th nowrap="nowrap" colspan="4"><div align="center"><s:text name="label.userGroupName" /> : <s:textfield id="usgName" name="searchUserGroupBean.usgName" maxlength="30" /></div></th>
              </tr>
              <tr>
                <th>&nbsp;</th>
                <td>&nbsp;</td>
                <th>&nbsp;</th>
                <td>&nbsp;</td>
              </tr>
            </table>
          </div>
      </div>
      <div class="button">
        <table align="center">
            <tr>
              <td><authz:authorize granted="<%=PrivConst.S070101%>" ><span id="button"><a href="javascript:onClickSearch();"><span><s:text name="button.search" /></span></a></span></authz:authorize></td>
              <td><authz:authorize granted="<%=PrivConst.S070200%>" ><span id="button"><a href="javascript:onClickAdd();"><span><s:text name="button.add" /></span></a></span></authz:authorize></td>
              <td><span id="button"><a href="javascript:onClickCancel();" ><span><s:text name="button.cancel" /></span></a></span></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
            </tr>
        </table>
      </div>
        <!-- / search result -->
        <!-- search result -->
        
        <s:if test="%{resultList != null}">
        
        	<s:if test="%{resultList.size == 0}">
        	<div id="searchResult">
      			<div class="hr"></div>
      			<div class="subTopic">Results</div>
      			<div class="tableSearchResult">
        			<div class="alert"><%=ProjectConstant.MESSAGE_NO_RECORD_FOUND%></div>
       			</div>
    		</div>
        	</s:if>
        	<s:else>
          <div id="searchResult">
          <div class="hr"></div>
          <div class="subTopic">Results</div>
          <div class="tableSearchResult">
            <div class="pagefound">
              <table>
                <tr>
                  <td class="L">
                  	<agi:pagenavi paging="${pagingBean}" />
                    </td>
                  <td class="R">
                    <agi:pagenum paging="${pagingBean}" callback="changePage"  />
                  </td>
                </tr>
              </table>
            </div>
            <table>
              <tr>
                <th nowrap="nowrap" class="checkbox">&nbsp;</th>
                <th><a href="javascript:sortUserGroupname()">User Group Name</a></th>
                <th>Status</th>
              </tr>
              
              <s:iterator value="resultList" status="rowstatus" id="resultList" >
              	<tr>
                	<td class="icon"><s:set name="selectedId" value="usgId"/>
                		<a href="javascript:onClickView('<s:property value="#selectedId"/>');"><img src="${requestScope.imageBase}/icons/view.gif" alt="View" /></a>
                		<a href="javascript:onClickEdit('<s:property value="#selectedId"/>');"><img src="${requestScope.imageBase}/icons/edit.gif" alt="Edit" /></a>
                	</td>
                	<td><s:property value="usgName"/></td>
                	<td><s:property value="usgStatus"/></td>
              	</tr>
              </s:iterator>
            </table>
            
            <div class="pagefound">
			  <table>
                <tr>
                  <td class="L">
                  	<agi:pagefound paging="${pagingBean}" />
                  	&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
                  	<agi:pagedisplay id="rowsPerPage" name="pagingBean.rowsPerPage" paging="${pagingBean}" />
                  	</td>
                  <td class="R">
                    <agi:pagenum paging="${pagingBean}" callback="changePage" />
                  </td>
                </tr>
              </table>
              </div>
            
            <br />
          </div>
          </div>
        </s:else>
        	
        </s:if>
 
        </s:form>
    </div>

<script>
function onClickSearch(){
    $j("#mainForm").attr("action","roleManagement-search.htm"); 
    $j("#clickSearchFlag").val("true"); 
  	$j("#mainForm").submit();
}

function onClickAdd(){
    $j("#mainForm").attr("action","roleManagement-preAdd.htm"); 
  	$j("#mainForm").submit();
}

function onClickCancel(){
    $j("#mainForm").attr("action","roleManagement-end.htm"); 
  	$j("#mainForm").submit();
}

function onClickView(selectedId){
	$j("#selectedId").val(selectedId);
    $j("#mainForm").attr("action","roleManagement-view.htm"); 
  	$j("#mainForm").submit();
}

function onClickEdit(selectedId){
	$j("#selectedId").val(selectedId);
    $j("#mainForm").attr("action","roleManagement-preEdit.htm"); 
  	$j("#mainForm").submit();
}

function changePage(page) {
	$j("#currentPage").val(page);
	$j("#mainForm")
		.attr("action","roleManagement-search.htm")
		.submit(); 
}

//add by pimonrath (kae) 08/11/2010
function sortUserGroupname(){
	var sortMode = $j("#sortMode").val();
	
	if(sortMode == "ASC"){
		 $j("#sortMode").val("DESC"); 
	}else if(sortMode == "DESC"){
		$j("#sortMode").val("ASC");
	}

	$j("#mainForm").attr("action","roleManagement-search.htm").submit();
	
}
</script>